﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using TianYa.API.Response;
using TianYa.API.Request;
using G.Navigate;

namespace TianYa.View
{
    public partial class Index : GBasePage
    {
        public Index()
        {
            InitializeComponent();
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            listboxRecent.ItemsSource = GloabalData.Instance.TianYaDataBase.BrowserRecordeTable.OrderByDescending(c => c.TimeStamp).Take(40);
            listboxFavir.ItemsSource = GloabalData.Instance.TianYaDataBase.FavoiratTable.ToList();
        }

        private void tilePlate_Click(object sender, RoutedEventArgs e)
        {
            //this.NavigationService.Navigate(string.Format("/View/PlatePostListPage.xaml?plateid={0}", "worldlook"));
            this.NavigationService.Navigate(string.Format("/View/PlatePage.xaml"));
        }

        private void listboxRecent_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listboxRecent.SelectedItem != null)
            {
                Data.BrowserRecorde re = listboxRecent.SelectedItem as Data.BrowserRecorde;
                this.NavigationService.Navigate(string.Format("/View/PostContenPage.xaml?plateid={0}&postid={1}&name={2}", re.PlateId, re.PostId, HttpUtility.UrlEncode(re.Name)));
                listboxRecent.SelectedItem = null;
            }
        }

        private void listboxFavir_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listboxFavir.SelectedItem != null)
            {
                Data.Favoirat fa = listboxFavir.SelectedItem as Data.Favoirat;
                this.NavigationService.Navigate(string.Format("/View/PostContenPage.xaml?plateid={0}&postid={1}&name={2}", fa.PlateId, fa.PostId, HttpUtility.UrlEncode(fa.Name)));
                listboxFavir.SelectedItem = null;
            }
        }
    }
}